package ru.job4j.generics;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Generics {

    public static void main(String[] args) {
        Generics gen = new Generics();
        List<Animal> first = new ArrayList<>();
        List<Predator> second = new ArrayList<>();
        List<Tiger> third = new ArrayList<>();
        first.add(new Animal("wood", "meet"));
        second.add(new Predator("wood", "meet"));
        third.add(new Tiger("wood", "meet"));

        gen.printObject(first);
        gen.printObject(second);
        gen.printObject(third);
        System.out.println();

        /*
        gen.printBoundedWildCard(first);
        */
        gen.printBoundedWildCard(second);
        gen.printBoundedWildCard(third);
        System.out.println();

        gen.printLowerBoundedWildCard(first);
        gen.printLowerBoundedWildCard(second);
        /*
        gen.printLowerBoundedWildCard(third);
        */
    }

      /*
      public void printObject(List<Object> list) {
          for (Iterator<Object> it = list.iterator(); it.hasNext();) {
      */
      public void printObject(List<?> list) {
          for (Iterator<?> it = list.iterator(); it.hasNext();) {
            Object next = it.next();
            System.out.println("Текущий элемент: " + next);
        }
    }

      /*
      public void printBoundedWildCard(List<Predator> list) {
          for (Iterator<Predator> it = list.iterator(); it.hasNext();)
      */
      public void printBoundedWildCard(List<? extends Predator> list) {
          for (Iterator<? extends Predator> it = list.iterator(); it.hasNext();) {
            Object next = it.next();
            System.out.println("Текущий элемент: " + next);
        }
    }

      /*
      public void printLowerBoundedWildCard(List<Predator> list) {
          for (Iterator<Predator> it = list.iterator(); it.hasNext();) {
      */
      public void printLowerBoundedWildCard(List<? super Predator> list) {
          for (Iterator<? super Predator> it = list.iterator(); it.hasNext();) {
            Object next = it.next();
            System.out.println("Текущий элемент: " + next);
        }
    }
}
